package com.ucode.crm.builder;

import java.util.Date;
import org.springframework.stereotype.Component;
import com.ucode.crm.dictionary.FollowupContentType;
import com.ucode.crm.dictionary.ModuleType;
import com.ucode.crm.mode.Business;
import com.ucode.crm.mode.Customer;
import com.ucode.crm.mode.FollowupRecord;
import com.ucode.tool.util.IdentifyUtils;

@Component
public class FollowupRecordBuilder {

    public FollowupRecord buildByCustomer(Customer customer){
        return build(customer.getName(),customer.getId(),customer.getId(),ModuleType.customer,customer.getCreateUserId());
    }
    
    public FollowupRecord buildByBusiness(Business business){
        return build(business.getName(),business.getCustomerId(),business.getId(),ModuleType.business,business.getCreateUserId());
    }
    
    private FollowupRecord build(String name,Long customerId,Long activityId,ModuleType activityType,Long createUserId){
        Date now = new Date();
        FollowupRecord followupRecord = new FollowupRecord();
        followupRecord.setId(IdentifyUtils.getDefaultSnowflakeId());
        followupRecord.setContentType(FollowupContentType.sys.code);
        followupRecord.setContent("创建了"+activityType.getMessage()+":"+name);
        followupRecord.setFileId(0L);
        followupRecord.setCustomerId(customerId);
        followupRecord.setActivityId(activityId);
        followupRecord.setActivityType(activityType.code);
        followupRecord.setCreateUserId(createUserId);
        followupRecord.setCreatedTime(now);
        followupRecord.setUpdatedTime(now);
        return followupRecord;
    }
}
